﻿using Abp.vNext.WT.WebApi.Issues;
using System;
using System.Threading.Tasks;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Guids;
using Volo.Abp.MultiTenancy;

namespace Abp.vNext.WT.WebApi;

public class WebApiTestDataSeedContributor : IDataSeedContributor, ITransientDependency
{
    //private readonly IIssueRepository _issueRepository;
    private readonly IRepository<Issue, Guid> _issueRepository;
    private readonly IGuidGenerator _guidGenerator;
    private readonly ICurrentTenant _currentTenant;

    public WebApiTestDataSeedContributor(
        IRepository<Issue, Guid> issueRepository,
        IGuidGenerator guidGenerator,
        ICurrentTenant currentTenant)
    {
        _issueRepository = issueRepository;
        _guidGenerator = guidGenerator;
        _currentTenant = currentTenant;
    }

    //public WebApiTestDataSeedContributor(IIssueRepository issueRepository)
    //{
    //    _issueRepository= issueRepository;
    //}

    public async Task SeedAsync(DataSeedContext context)
    {
        /* Seed additional test data... */

        using (_currentTenant.Change(context?.TenantId))
        {
            if (await _issueRepository.GetCountAsync() > 0)
            {
                return;
            }

            await _issueRepository.InsertAsync(
            //得在实体类添加有参构造
            new Issue(
            id: TestData.Issue1Id,
            assignedUserId: TestData.User1Id,
            title: "问题1",
            text: "内容1"
            ));
            await _issueRepository.InsertAsync(
            new Issue(
            id: TestData.Issue2Id,
            assignedUserId: TestData.User2Id,
            title: "问题2",
            text: "内容2"
            ));
        }

        //await _issueRepository.InsertAsync(
        //    //得在实体类添加有参构造
        //    new Issue(
        //    id: TestData.Issue1Id,
        //    assignedUserId: TestData.User1Id,
        //    title: "问题1",
        //    text: "内容1"
        //    ));

        //await _issueRepository.InsertAsync(
        //    new Issue(
        //    id: TestData.Issue2Id,
        //    assignedUserId: TestData.User2Id,
        //    title: "问题2",
        //    text: "内容2"
        //    ));

        //return Task.CompletedTask;
    }

    public static class TestData
    {
        public static Guid User1Id = Guid.Parse("41951813-5CF9-4204-8B18-CD765DBCBC9B");
        public static Guid User2Id = Guid.Parse("2DAB4460-C21B-4925-BF41-A52750A9B999");

        public static Guid Issue1Id = Guid.Parse("41951813-5CF9-4204-8B18-CD765DBCBC9B");
        public static Guid Issue2Id = Guid.Parse("2DAB4460-C21B-4925-BF41-A52750A9B999");
        public static Guid Issue3Id = Guid.Parse("2DAB4460-C21B-4925-BF41-A53750A9B999");
    }
}
